package com.srini.util;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vssr.persist.DomainObject;

public class LeaveHolyDays {

	public static Map getHolidays(int userId, Connection con) {
		String query = "select date, type from leaves where userid=" + userId + " or type='1'";
		List leavesList = null; 
		List list = DomainObject.getDBRecords(query, con);
		Map days = new HashMap();
		Collection collection = null;
		for (Object object : list) {
			leavesList = new ArrayList();
			collection = (Collection)object;
			leavesList.addAll(collection);
			if (days.containsKey(leavesList.get(0))) {
				List l = (List)days.get(leavesList.get(0));
				l.add(leavesList.get(1));
			}else {
				days.put(leavesList.get(0), leavesList.subList(1, leavesList.size()));
			}
		}
		return days;
	}
	
	public static void main(String[] args) {
		Map leaves = getHolidays(3, new ConnectionUtil().getConnection());
		System.out.println(leaves);
	}
}
